<?php
class User extends AppModel {
	var $name = 'User';
	var $displayField = 'company';
	var $chaptcha;
	var $validate = array(
		'email' => array(
			'email' => array(
				'rule' => array('email'),
				'message' => 'Please enter a valid email address in the form',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
			'unique' => array(
				'rule' => 'isUnique',
		        'message' => 'This email has already been taken.'
	        )
		),
		'password' => array(
		            'rule' => array('minLength', '8'),
		            'message' => 'Mimimum 8 characters long'
		),		
		'user_password' => array(
            'rule' => array('minLength', '8'),
            'message' => 'Mimimum 8 characters long'
        ),
		'confirm_password' => array(
		            'rule' => array('minLength', '8'),
		            'message' => 'Mimimum 8 characters long'
		),        
		'first_name' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Please enter a valid first name',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'last_name' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Please enter a valid last name',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'captcha' => array(
		            'rule' => array('checkCaptcha'),
		            'message' => 'Please rewrite corect code from image.'
		)
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = 'Upload';
	
	var $hasMany = array(

	);

	function checkCaptcha($check){
		App::import('Component', 'SessionComponent'); 
		$session = new SessionComponent(); 
		$auth = $session->read("Captcha");	
// 		debug(array($auth,$check));	
		return ($auth == $check['captcha']) ? true : false;
	}
}
